home *** CD-ROM | disk | FTP | other *** search
- package sub_arctic.lib;
-
- import sub_arctic.input.inout_draggable;
- import sub_arctic.input.pressable;
- import sub_arctic.input.callback_object;
- import sub_arctic.input.event;
-
- import sub_arctic.output.loaded_image;
- import sub_arctic.output.drawable;
-
-
- /**
- * This class is a common superclass for checkbox and radio_button. This
- * object currently may be instantiated to get the old subarctic look,
- * but this may go away in the future.
- *
- * @author Scott Hudson
- */
- public class toggle extends multi_button implements inout_draggable, pressable {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Link for circular list of radio button group. If we are not in a
- * group, this will refer to ourselves.
- */
- protected toggle _group_link;
-
- /**
- * Link for circular list of radio button group. If we are not in a
- * group, this will refer to ourselves.
- * @return toggle our link in the circular group list.
- */
- public toggle group_link() {return _group_link;}
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Full constructor. The two image sets should each have two entries. The
- * entries at index 0 provide appearance for the 0 (off) state and the
- * transition between state 0 and state 1 respectively (index 1 similarly
- * maps to state 1). The transition set may be coded as null in which
- * case the next state image is used when a transition is needed. Otherwise
- * the two image sets must be the same size.
- *
- * @param int x x position of the toggle.
- * @param int y y position of the toggle.
- * @param loaded_image[] st_looks set of images for normal looks.
- * @param loaded_image[] trans_looks set of images for looks during
- * transitions between states (can be
- * null to denote not special transition
- * appearances).
- * @param toggle group_with toggle to group this with to get
- * radio_button semantics (or null for
- * no grouping).
- * @param callback_object call_obj object that gets callbacks about
- * state changes.
- */
- public toggle(
- int x,
- int y,
- loaded_image[] st_looks,
- loaded_image[] trans_looks,
- toggle group_with,
- callback_object call_obj)
- {
- super(x, y, st_looks, trans_looks, call_obj);
-
- /* start with no group */
- _group_link = this;
-
- /* add to group if requested */
- if (group_with != null) add_to_group_of(group_with);
-
- /* make sure the image sets are usable */
- if (st_looks == null || st_looks.length != 2)
- throw new sub_arctic_error("Wrong number of images passed to toggle()");
-
- if (trans_looks != null && trans_looks.length != st_looks.length)
- throw new sub_arctic_error("Normal and transition image sets of unequal " +
- "size passed to toggle()");
- }
-
- //had:
- //* @exception bad_value if wrong number of images are passed
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Default appearance constructor.
- *
- * @param int x x position of the toggle.
- * @param int y y position of the toggle.
- * @param callback_object call_obj object that gets callbacks about
- * state changes.
- */
- public toggle( int x, int y, callback_object call_obj)
- {
- this(x,y, default_look(),default_transition(), null, call_obj);
- }
-
- //had:
- //* @exception bad_value PROPAGATED.
- //* @exception general PROPAGATED.
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Override set_cur_state to reset other group members (if any) if we
- * are being set (put in state 1).
- * @param int st new state.
- */
- public void set_cur_state(int st)
- {
- /* let super class set our local state */
- super.set_cur_state(st);
-
- /* if we are being set, run trough rest of group (if any) and reset */
- if (cur_state() == 1)
- for (toggle t = group_link(); t != this; t = t.group_link())
- t.set_cur_state(0);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Override next_state to provide group behavior. If we are not in a
- * group then we just toggle. However, if we are in a group then we
- * transition from off to on, but not on to off (we get reset by another
- * group member being set).
- * @return int the state we will enter if activated again.
- */
- public int next_state()
- {
- /* if there is no group then we just use the default */
- if (_group_link == this)
- return super.next_state();
-
- /* otherwise transitions are 0 to 1 and 1 to 1 */
- return 1;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Return the previous toggle in our circular group list.
- * @return toggle the toggle before us in the group list.
- */
- protected toggle group_prev()
- {
- /* find the toggle in the circular group list that points to us */
- for (toggle t = _group_link; ; t = t._group_link)
- if (t._group_link == this) return t;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Drop us from our current group */
- public void drop_from_group()
- {
- /* take us out of the circular list */
- group_prev()._group_link = _group_link;
-
- /* make us a singleton group */
- _group_link = this;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Add us to the group the given toggle is in.
- * @param toggle other the toggle whose group we are joining.
- */
- public void add_to_group_of(toggle other)
- {
- /* make sure we are not in some other group */
- drop_from_group();
-
- /* put us in other's group */
- _group_link = other._group_link;
- other._group_link = this;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Images for default normal appearance of a toggle. */
- protected static loaded_image[] _default_look = std.toggle_image_set();
-
- /** Images for default normal appearance of a toggle. */
- public static loaded_image[] default_look() { return _default_look; }
-
- /** Images for default transition appearance of a toggle. By default this
- * is null and signifies that we just use the next state image for the
- * transition.
- */
- public static loaded_image[] default_transition() { return null; }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-